package com.xyhuo.leetcode.y2025;

public class AddDigits {

    public static void main(String[] args) {
        AddDigits a = new AddDigits();
        a.addDigits(38);
    }

    public int addDigits(int num) {
        while (true) {
            num = cal(num);
            if (num < 10) {
                return num;
            }
        }
    }

    private int cal(int num) {
        int ans = 0;
        if (num > 9) {
            ans += num % 10;
            num = num / 10;
        }
        return ans + num;
    }
}
